package com.solcoo.merchant.ui.welcome;

import android.content.Intent;
import android.os.Bundle;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.TextView;

import com.solcoo.merchant.R;
import com.solcoo.merchant.base.BaseActivity;
import com.solcoo.merchant.manager.UserManager;
import com.solcoo.merchant.ui.login.LoginActivity;
import com.solcoo.merchant.ui.menu.MenuActivity;

public class WelComeActivity extends BaseActivity {
	private static final long DURATION_TIME = 2000L;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.welcome);
		// 全屏
		this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);
		// 开启动画
		TextView logoBg = (TextView) findViewById(R.id.welcome_view);
		Animation logoAnimation = AnimationUtils.loadAnimation(this,
				R.anim.welcome);
		logoAnimation.setDuration(DURATION_TIME);
		logoAnimation.setAnimationListener(mAnimationListener);
		logoBg.startAnimation(logoAnimation);

	}

	private boolean isLogin() {
		return UserManager.getInstance().getUser() != null;
	}

	private AnimationListener mAnimationListener = new AnimationListener() {

		@Override
		public void onAnimationStart(Animation animation) {
		}

		@Override
		public void onAnimationRepeat(Animation animation) {
		}

		@Override
		public void onAnimationEnd(Animation animation) {
			if (isLogin()) {
				Intent it = new Intent(WelComeActivity.this, MenuActivity.class);
				startActivity(it);
			} else {
				Intent it = new Intent(WelComeActivity.this,
						LoginActivity.class);
				startActivity(it);
			}
		}
	};
}
